package com.ruge._08_springboot_springdata_jpa.controller._02_entityManager;

import com.ruge._08_springboot_springdata_jpa.Application;
import com.ruge._08_springboot_springdata_jpa.model.base.BaseModel;
import com.ruge._08_springboot_springdata_jpa.model.base.UnionPk;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.test.context.SpringBootTest;
import org.springframework.test.context.junit4.SpringJUnit4ClassRunner;
import org.springframework.transaction.annotation.Transactional;

import javax.persistence.EntityManager;

/**
 * 创建人 ：爱丽丝、如歌
 * 创建时间 ：2019-07-05  22:43
 * 描述 ：
 */
@RunWith(SpringJUnit4ClassRunner.class)
@SpringBootTest(classes = Application.class)//这里是启动类
public class TestUpdate {
    @Autowired
    private EntityManager entityManager;

    @Test
    @Transactional
    public void test() {
        BaseModel model = new BaseModel();
        UnionPk pk = new UnionPk();
       // pk.setUserId(17);
       // model.setUnionPk(pk);
        model.setUserName("张三更新");
        //保存或更新数据
        entityManager.merge(model);
        entityManager.flush();
        System.out.println("===========更新成功===============");
    }
}
